s = "aaaaaaa" |
l = str(l) |
l = len(s) |
print(c + l) |
c = s[0] |
1 | s = "aaaaaaa" |
2 | c = s[0] |
3 | l = len(s) |
4 | l = str(l) |
5 | print(c + l) |
n = s[1:] |
s = "a12" |
c = s[0] |
n = int(n) |
print(c*n) |
1 | s = "a12" |
2 | c = s[0] |
3 | n = s[1:] |
4 | n = int(n) |
5 | print(c*n) |
compressed = "" |
s = "aaaabbbbcccc" |
count = 1 |
for i in range(1, len(s)): |
print(compressed) |
count += 1 |
compressed += last_char + str(count) |
if s[i] == last_char: |
last_char = s[0] |
count = 1 |
last_char = s[i] |
else: |
compressed += last_char + str(count) |
compressed = "" |
s = "aaaabbbbcccc" |
count = 1 |
for i in range(1, len(s)): |
print(compressed) |
        count += 1 |
        compressed += last_char + str(count) |
    if s[i] == last_char: |
last_char = s[0] |
        count = 1 |
        last_char = s[i] |
    else: |
compressed += last_char + str(count) |
1 | s = "aaaabbbbcccc" |
2 | |
3 | compressed = "" |
4 | count = 1 |
5 | last_char = s[0] |
6 | for i in range(1, len(s)): |
7 |     if s[i] == last_char: |
8 |         count += 1 |
9 |     else: |
10 |         compressed += last_char + str(count) |
11 |         last_char = s[i] |
12 |         count = 1 |
13 | |
14 | compressed += last_char + str(count) |
15 | print(compressed) |
num = "" |
if s[i].isdigit() == False: |
print(decompressed) |
num = "" |
s = "a3b2c1" |
decompressed = "" |
for i in range(1,len(s)): |
decompressed = decompressed + char * int(num) |
char = s[0] |
else: |
num = num + s[i] |
decompressed = decompressed + char * int(num) |
char = s[i] |
num = "" |
    if s[i].isdigit() == False: |
print(decompressed) |
        num = "" |
s = "a3b2c1" |
decompressed = "" |
for i in range(1,len(s)): |
        decompressed = decompressed + char * int(num) |
char = s[0] |
    else: |
        num = num + s[i] |
decompressed = decompressed + char * int(num) |
        char = s[i] |
1 | s = "a3b2c1" |
2 | |
3 | decompressed = "" |
4 | num = "" |
5 | char = s[0] |
6 | for i in range(1,len(s)): |
7 |     if s[i].isdigit() == False: |
8 |         decompressed = decompressed + char * int(num) |
9 |         char = s[i] |
10 |         num = "" |
11 |     else: |
12 |         num = num + s[i] |
13 | decompressed = decompressed + char * int(num) |
14 | print(decompressed) |
15 |
count = 1 |
compressed = "" |
if data[i] == last_char: |
compressed += last_char + str(count) |
f.close() |
print(len(data),">",len(compressed)) |
data = f.read() |
f = open(file_name + ".txt", 'r') |
else: |
compressed_file_name = file_name + "Compressed.txt" |
f.close() |
last_char = data[i] |
f = open(compressed_file_name, 'w') |
last_char = data[0] |
count = 1 |
f.write(compressed) |
def compress_file(file_name): |
count += 1 |
compressed += last_char + str(count) |
for i in range(1, len(data)): |
    count = 1 |
    compressed = "" |
        if data[i] == last_char: |
    compressed += last_char + str(count) |
    f.close() |
    print(len(data),">",len(compressed)) |
    data = f.read() |
    f = open(file_name + ".txt", 'r') |
        else: |
    compressed_file_name = file_name + "Compressed.txt" |
    f.close() |
            last_char = data[i] |
    f = open(compressed_file_name, 'w') |
    last_char = data[0] |
            count = 1 |
    f.write(compressed) |
def compress_file(file_name): |
            count += 1 |
            compressed += last_char + str(count) |
    for i in range(1, len(data)): |
1 | def compress_file(file_name): |
2 |     f = open(file_name + ".txt", 'r') |
3 |     data = f.read() |
4 |     f.close() |
5 |      |
6 |     compressed = "" |
7 |     count = 1 |
8 |     last_char = data[0] |
9 |      |
10 |     for i in range(1, len(data)): |
11 |         if data[i] == last_char: |
12 |             count += 1 |
13 |         else: |
14 |             compressed += last_char + str(count) |
15 |             last_char = data[i] |
16 |             count = 1 |
17 |      |
18 |     compressed += last_char + str(count) |
19 |     compressed_file_name = file_name + "Compressed.txt" |
20 |      |
21 |     f = open(compressed_file_name, 'w') |
22 |     f.write(compressed) |
23 |     f.close() |
24 |     print(len(data),">",len(compressed)) |
decompressed_file_name = file_name.replace("Compressed", "") + ".txt" |
f.write(decompressed) |
f.close() |
else: |
data = f.read() |
char = data[0] |
decompressed = decompressed + char * int(num) |
num = "" |
num = "" |
f = open(file_name + ".txt", 'r') |
decompressed = decompressed + char * int(num) |
char = data[i] |
for i in range(1,len(data)): |
f = open(decompressed_file_name, 'w') |
f.close() |
decompressed = "" |
if data[i].isdigit() == False: |
def decompress_file(file_name): |
num = num + data[i] |
    decompressed_file_name = file_name.replace("Compressed", "") + ".txt" |
    f.write(decompressed) |
    f.close() |
        else: |
    data = f.read() |
    char = data[0] |
            decompressed = decompressed + char * int(num) |
    num = "" |
            num = "" |
    f = open(file_name + ".txt", 'r') |
    decompressed = decompressed + char * int(num) |
            char = data[i] |
    for i in range(1,len(data)): |
    f = open(decompressed_file_name, 'w') |
    f.close() |
    decompressed = "" |
        if data[i].isdigit() == False: |
def decompress_file(file_name): |
            num = num + data[i] |
1 | def decompress_file(file_name): |
2 |     f = open(file_name + ".txt", 'r') |
3 |     data = f.read() |
4 |     f.close() |
5 | |
6 |     decompressed = "" |
7 |     num = "" |
8 |     char = data[0] |
9 |     for i in range(1,len(data)): |
10 |         if data[i].isdigit() == False: |
11 |             decompressed = decompressed + char * int(num) |
12 |             char = data[i] |
13 |             num = "" |
14 |         else: |
15 |             num = num + data[i] |
16 |     decompressed = decompressed + char * int(num) |
17 |     decompressed_file_name = file_name.replace("Compressed", "") + ".txt" |
18 |      |
19 |     f = open(decompressed_file_name, 'w') |
20 |     f.write(decompressed) |
21 |     f.close() |
def compress_file(file_name): |
print(len(data),">",len(compressed)) |
else: |
compressed = "" |
f.close() |
for i in range(1, len(data)): |
last_char = data[i] |
f = open(compressed_file_name, 'w') |
last_char = data[0] |
data = f.read() |
if data[i] == last_char: |
f = open(file_name + ".txt", 'r') |
compressed += last_char + str(count) |
compressed_file_name = file_name + "Compressed.txt" |
f.write(compressed) |
f.close() |
count = 1 |
count += 1 |
count = 1 |
compressed += last_char + str(count) + "|" #Add a divider to show when one number ends |
def compress_file(file_name): |
    print(len(data),">",len(compressed)) |
        else: |
    compressed = "" |
    f.close() |
    for i in range(1, len(data)): |
            last_char = data[i] |
    f = open(compressed_file_name, 'w') |
    last_char = data[0] |
    data = f.read() |
        if data[i] == last_char: |
    f = open(file_name + ".txt", 'r') |
    compressed += last_char + str(count) |
    compressed_file_name = file_name + "Compressed.txt" |
    f.write(compressed) |
    f.close() |
            count = 1 |
            count += 1 |
    count = 1 |
            compressed += last_char + str(count) + "|" #Add a divider to show when one number ends |
1 | def compress_file(file_name): |
2 |     f = open(file_name + ".txt", 'r') |
3 |     data = f.read() |
4 |     f.close() |
5 |      |
6 |     compressed = "" |
7 |     count = 1 |
8 |     last_char = data[0] |
9 |      |
10 |     for i in range(1, len(data)): |
11 |         if data[i] == last_char: |
12 |             count += 1 |
13 |         else: |
14 |             compressed += last_char + str(count) + "|" #Add a divider to show when one number ends |
15 |             last_char = data[i] |
16 |             count = 1 |
17 |      |
18 |     compressed += last_char + str(count) |
19 |     compressed_file_name = file_name + "Compressed.txt" |
20 |      |
21 |     f = open(compressed_file_name, 'w') |
22 |     f.write(compressed) |
23 |     f.close() |
24 |     print(len(data),">",len(compressed)) |
def decompress_file(file_name): |
f = open(decompressed_file_name, 'w') |
f.close() |
binary = data.split("|") |
decompressed = "" |
f.write(decompressed) |
f.close() |
decompressed_file_name = file_name.replace("Compressed","") + ".txt" |
for x in range(len(binary)): |
data = f.read() |
f = open(file_name + ".txt", 'r') |
decompressed = decompressed + binary[x][0] * int(binary[x][1:]) |
def decompress_file(file_name): |
    f = open(decompressed_file_name, 'w') |
    f.close() |
    binary = data.split("|") |
    decompressed = "" |
    f.write(decompressed) |
    f.close() |
    decompressed_file_name = file_name.replace("Compressed","") + ".txt" |
    for x in range(len(binary)): |
    data = f.read() |
    f = open(file_name + ".txt", 'r') |
        decompressed = decompressed + binary[x][0] * int(binary[x][1:]) |
1 | def decompress_file(file_name): |
2 |     f = open(file_name + ".txt", 'r') |
3 |     data = f.read() |
4 |     f.close() |
5 | |
6 |     binary = data.split("|") |
7 |     decompressed = "" |
8 |     for x in range(len(binary)): |
9 |         decompressed = decompressed + binary[x][0] * int(binary[x][1:]) |
10 |      |
11 |     decompressed_file_name = file_name.replace("Compressed","") + ".txt" |
12 |     f = open(decompressed_file_name, 'w') |
13 |     f.write(decompressed) |
14 |     f.close() |
key = "" |
continue |
f.close() |
f.write(everything) |
for word in words: |
count = {} |
count[word] = 1 |
f = open("HG Compressed.txt","w") |
key += rare_characters[x]+sorted_words[x][0]+"\n" |
f.write(key) |
count[word] = count[word] + 1 |
f.close() |
print(len(everything)) |
f = open("key.txt","w") |
if len(word) < 4: |
sorted_words = sorted(count.items(), key=lambda item: item[1],reverse=True) |
everything = everything.replace(sorted_words[x][0],rare_characters[x]) |
lines = everything.split("\n") |
if word not in count: |
for x in range(len(rare_characters)): |
rare_characters = ['~', '|', '^', '{', '}', '[', ']', '<', '>', '#', '&', '*', '\\', '/', '@','%', '+', '=', '$', '€', '£', '¥', '°', '¢', '¬'] |
word = word.replace(".","").replace(",","") |
f = open("./ALevel Answers Folder/Hitchhikers Guide.txt","r") |
everything = f.read() |
print(len(everything)) |
for line in lines: |
words = line.split(" ") |
f.close() |
key = "" |
            continue |
f.close() |
f.write(everything) |
    for word in words: |
count = {} |
            count[word] = 1 |
f = open("HG Compressed.txt","w") |
    key += rare_characters[x]+sorted_words[x][0]+"\n" |
f.write(key) |
        count[word] = count[word] + 1 |
f.close() |
print(len(everything)) |
f = open("key.txt","w") |
        if len(word) < 4: |
sorted_words = sorted(count.items(), key=lambda item: item[1],reverse=True) |
    everything = everything.replace(sorted_words[x][0],rare_characters[x]) |
lines = everything.split("\n") |
        if word not in count: |
for x in range(len(rare_characters)): |
rare_characters = ['~', '|', '^', '{', '}', '[', ']', '<', '>', '#', '&', '*', '\\', '/', '@','%', '+', '=', '$', '€', '£', '¥', '°', '¢', '¬'] |
        word = word.replace(".","").replace(",","") |
f = open("./ALevel Answers Folder/Hitchhikers Guide.txt","r") |
everything = f.read() |
print(len(everything)) |
for line in lines: |
    words = line.split(" ") |
f.close() |
1 | rare_characters = ['~', '|', '^', '{', '}', '[', ']', '<', '>', '#', '&', '*', '\\', '/', '@','%', '+', '=', '$', '€', '£', '¥', '°', '¢', '¬'] |
2 | f = open("./ALevel Answers Folder/Hitchhikers Guide.txt","r") |
3 | everything = f.read() |
4 | lines = everything.split("\n") |
5 | |
6 | f.close() |
7 | count = {} |
8 | for line in lines: |
9 |     words = line.split(" ") |
10 |     for word in words: |
11 |         word = word.replace(".","").replace(",","") |
12 |         if len(word) < 4: |
13 |             continue |
14 |         if word not in count: |
15 |             count[word] = 1 |
16 |         count[word] = count[word] + 1 |
17 | print(len(everything)) |
18 | sorted_words = sorted(count.items(), key=lambda item: item[1],reverse=True) |
19 | key = "" |
20 | for x in range(len(rare_characters)): |
21 |     everything = everything.replace(sorted_words[x][0],rare_characters[x]) |
22 |     key += rare_characters[x]+sorted_words[x][0]+"\n" |
23 | print(len(everything)) |
24 | f = open("HG Compressed.txt","w") |
25 | f.write(everything) |
26 | f.close() |
27 | |
28 | f = open("key.txt","w") |
29 | f.write(key) |
30 | f.close() |